package com.test.javafaq_faq.service.impl;

import com.test.javafaq_commons.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class RibbonClient {

    @Autowired
    RestTemplate restTemplate;

    public Map<String,User> getTeachersMap(){
        String url = "http://sys-service/v1/users/master";
        User[] users = restTemplate.getForObject(url,User[].class);
        Map<String,User> masterMap = new HashMap<>();
        for (User u : users) {
            masterMap.put(u.getNickname(),u);
        }
        return masterMap;
    }
    //获取当前用户信息
    public User getUser(String username){
        String url = "http://sys-service/v1/auth/user?username={1}";
        User user = restTemplate.getForObject(url,User.class,username);
        return user;
    }

}
